<?php
apf_require_class("Bll_BLL");
/**
 * 与mail建立链接
 * @author dinglin
 */
class Bll_Flow_MailSync extends BLL{
    private static $mail;
    private function __clone(){}
    private static $instance = NULL;
    /**
     * @return Bll_Flow_MailSync
     */
    public static function get_instance(){
        if(self::$instance == NULL){
            self::$instance = new Bll_Flow_MailSync();
            self::$mail = Base_soap::get_instance()->create_soap();
        }
        return self::$instance;;
    }
    /**
     * 创建用户
     * @param string $user_ename
     * @param string $pwd
     */
    public function creat_user($user_ename,$domain_name="anjuke.com",$pwd='3edc1234'){
        $data = array(
                'provider_id' =>'1',
                'user_id'=>$user_ename,
                'org_id'=>"a",
                'password'=>$pwd,
                'attrs'=>'domain_name='.$domain_name.'&cos_id=1&user_status=0&quota_delta=0'
                );
        return self::$mail->createUser($data);
    }
    /**
     * 删除用户
     * @param string $mail
     */
    public function delete_user($mail){
        $data = array(
                "user_at_domain"=>$mail
                );
        return self::$mail->deleteUser($data);
    }
    /**
     * 获取企业id,姓名，性别
     * @param string $mail
     */
    public function getAttrs($mail){
        $data = array(
                "user_at_domain"=>$mail,
                "attrs"=>'true_name=&gender=&org_id='
                );
        return self::$mail->getAttrs($data);
    }
}
/**
 * soap 链接mail
 * @author dinglin
 */
class Base_soap{
    private function __construct(){}
    private function __clone(){}
    private static $instance = NULL;
    /**
     *
     * @return Base_soap
     */
    public static function get_instance(){
        if(self::$instance == NULL){
            self::$instance = new Base_soap();
        }
        return self::$instance;;
    }
    /**
     * @return SoapClient
     */
    public function create_soap(){
        $BASE_URL = 'http://mail.anjuke.com/apiws/services/API';
        try{
            $ws = @new SoapClient($BASE_URL.'?wsdl');
            $ws->__setLocation($BASE_URL);
            return $ws;
        }
        catch (Exception $e){
            //上线关闭
            echo $e->getMessage();
            return null;
        }
    }
}